package com.gdsz.libbasic.view.ui

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import androidx.databinding.ViewDataBinding
import com.gdsz.libbasic.extensions.getViewBinding


abstract class BaseDialog<VB : ViewDataBinding>(context: Context, themeResId: Int) :
    Dialog(context, themeResId), BaseBinding<VB> {

    protected val binding: VB by lazy(mode = LazyThreadSafetyMode.NONE) {
        getViewBinding(layoutInflater, null)
    }
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setCanceledOnTouchOutside(canceledOnTouchOutside())
        setCancelable(setCancelable())
        setContentView(binding.root)
        binding.initBinding(savedInstanceState)
    }



    open fun canceledOnTouchOutside(): Boolean = false


    open fun setCancelable(): Boolean = true


    protected var onClick: ((type: Int, data: Any?) -> Unit)? = null
    fun onClick(block: (type: Int, data: Any?) -> Unit) {
        onClick = block
    }








}